import request from '@/utils/request';

var apiUrl = process.env.apiUrl

// 添加用户
export async function addUserList(data) {
  return request(
    `/v1/account`,
    {
      method: 'POST',
      body: JSON.stringify(data.body),
    },
    apiUrl,
  );
}

// 分页获取用户列表
export async function getUserList(data) {
  return request(
    `/v1/account/list/${data.params.pageSize}/${data.params.pageNum}`,
    {
      method: 'GET',
      params: data.params,
    },
    apiUrl,
  );
}

// 获取用户详情
export async function getUserInfoById(data) {
  return request(
    `/v1/account/detail/${data.params.id}`,
    {
      method: 'GET',
    },
    apiUrl,
  );
}

// 修改用户信息
export async function updateUserInfoById(data) {
  return request(
    `/v1/account`,
    {
      method: 'PUT',
      body: JSON.stringify(data.body),
    },
    apiUrl,
  );
}

// 删除用户
export async function deleteUserInfoById(data) {
  return request(
    `/v1/account/${data.params.id}`,
    {
      method: 'DELETE',
    },
    apiUrl,
  );
}

// 启用/禁用用户
export async function getUserEnabled(data) {
  return request(
    `/v1/account/${data.body.id}/enabled/${data.body.enabled}`,
    {
      method: 'PUT',
    },
    apiUrl,
  );
}

//查询所有角色

export async function getAllRoleList() {
  return request(
    `/v1/role/all`,
    {
      method: 'GET',
    },
    apiUrl,
  );
}

//查询所有用户权限

export async function getAuthList() {
  return request(
    `/v1/auth/all`,
    {
      method: 'GET',
    },
    apiUrl,
  );
}

// 添加角色
export async function RoleAdd(data) {
  return request(
    `/v1/role`,
    {
      method: 'POST',
      body: JSON.stringify(data.body),
    },
    apiUrl,
  );
}

// 获取角色列表
export async function getRoleList(data) {
  return request(
    `/v1/role/list/${data.params.pageSize}/${data.params.pageNum}`,
    {
      method: 'GET',
      params: data.params,
    },
    apiUrl,
  );
}

// 获取角色详情
export async function getRoleInfoById(data) {
  return request(
    `/v1/role/detail/${data.params.id}`,
    {
      method: 'GET',
    },
    apiUrl,
  );
}

// 修改角色信息
export async function updateRoleInfoById(data) {
  return request(
    `/v1/role`,
    {
      method: 'PUT',
      body: JSON.stringify(data.body),
    },
    apiUrl,
  );
}

// 删除角色
export async function deleteRoleInfoById(data) {
  return request(
    `/v1/role/${data.params.id}`,
    {
      method: 'DELETE',
    },
    apiUrl,
  );
}
